package com.wisnews.service.sr.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wisnews.mapper.sr.CommentMapper;
import com.wisnews.pojo.sr.entity.Comment;
import com.wisnews.service.sr.ICommentService;
import com.wisnews.util.Constants;
import com.wisnews.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuyd
 * @since 2021-01-15
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Boolean saveComment(String newsId, String context){

        Comment comment = new Comment();

        comment.setCommentText(context);
        comment.setNewsId(newsId);
        comment.setCreatetime(DateUtil.getLocalDateTime());
        comment.setModifytime(DateUtil.getLocalDateTime());
        comment.setState(Constants.SYS_STATE.USE);

        return super.save(comment);
    }

    @Override
    public IPage<Comment> getComment4NewsId(String newsId,IPage iPage) {

       LambdaQueryWrapper<Comment> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StringUtils.isNotBlank(newsId),Comment::getNewsId,newsId)
        .eq(Comment::getState, Constants.SYS_STATE.USE);
        return  commentMapper.getComments(queryWrapper,iPage);
    }

    @Override
    public IPage<Comment> queryCommentList(Comment req, IPage<Object> iPage) {
            //这里添加评论条件更具req
        LambdaQueryWrapper<Comment> commentLambdaQueryWrapper = Wrappers.lambdaQuery();

        return  commentMapper.getComments(commentLambdaQueryWrapper,iPage);
    }
}
